package lbj.cyw.dp;

/*
* Offer46. 把数字翻译成字符串
*
*  加了判断的斐波那契shulie
* */
public class Offer46translateNum {
    public int translateNum(int num) {
        if(num<10){
            return 1;
        }
        String s = String.valueOf(num);
        char[] chars = s.toCharArray();
        int[] dp=new int[chars.length];
        dp[0]=1;
        dp[1]=chars[0]-'0'==1 || (chars[0]-'0'==2&&chars[1]-'0'<6)?2:1;
        for(int i=2;i<dp.length;i++){
            dp[i]=chars[i-1]-'0'==1 || (chars[i-1]-'0'==2&&chars[i]-'0'<6)?(dp[i-1]+dp[i-2]):dp[i-1];
        }
        return dp[chars.length-1];
    }

//    public int translateNum(int num) {
//        if(num<10){
//            return 1;
//        }
//        String s = String.valueOf(num);
//        char[] chars = s.toCharArray();
//        int[] dp=new int[s.length()];
//        dp[0]=1;
//        dp[1]=s.charAt(0)-'0'==1 || (s.charAt(0)-'0'==2&&s.charAt(1)-'0'<6)?2:1;
//        for(int i=2;i<dp.length;i++){
//            dp[i]=s.charAt(i-1)-'0'==1 || (s.charAt(i-1)-'0'==2&&s.charAt(i-1)-'0'<6)?(dp[i-1]+dp[i-2]):dp[i-1];
//        }
//        return dp[chars.length-1];
//    }
}
